import com.troyworks.hsmf.AEvent;
import com.troyworks.hsmf.test.ILightSwitch;
import com.troyworks.hsmf.Hsmf;
import com.troyworks.hsmf.Signal;
import com.troyworks.spring.Factory;
import com.troyworks.framework.bootstrapper.BootTraceLogger;
import com.troyworks.framework.events.IEventOracle;
/**
 * @author Troy Gardner
 */
class com.troyworks.hsmf.test.DimmingLightSwitch extends Hsmf implements ILightSwitch, IEventOracle{
	
	public static var TOGGLE_SIG : Signal = new Signal (USER_SIG.value + 0, "TOGGLE_SIG");
	public static var DIMMEDUP_SIG : Signal = new Signal (USER_SIG.value + 0, "DIMMEDUP_SIG");
	public static var DIMMEDDOWN_SIG : Signal = new Signal (USER_SIG.value + 0, "DIMMEDDOWN_SIG");
	
	
	private var timeline:MovieClip;
	public var light_mc:MovieClip;
	public var toggle_mc:MovieClip;
	
	private static var _a:Function = BootTraceLogger;
	function DimmingLightSwitch (tl : MovieClip)
	{
		super ();
		Q_INIT(this.s1_off);
		trace("BasicLightSwitch " +  this.light_mc);
		timeline = tl;
		this.toggle_mc.onRelease =this.createCallback(new AEvent(DimmingLightSwitch.TOGGLE_SIG));
		this.init(null);
		
				trace("got factory? " + Factory.className);
		//////////////////////////////////
		// setup the class mappings for the Spring style injection,
		// these might be passed in from global variables, or loaded in from 
		// loadVars, XML etc.,
		var obj:Object = new Object();
		obj["Logger"] = "com.troyworks.framework.bootstrapper.BootTraceLogger";
		trace("casting to event oracle " + IEventOracle(this));
		obj["Oracle"] =IEventOracle(this);
		/////////////////////////////////
		//Configure the Generic Factory
		trace("Configuring Factory " + Factory); 
		Factory.registerImplementers(obj);
		//
		Object.registerClass("DimmedDownFrameTracker", com.troyworks.hsmf.test.DimmedDownFrameTracker  );
		Object.registerClass("DimmedUpFrameTracker",com.troyworks.hsmf.test.DimmedUpFrameTracker  );
		
	}	
	public function s1_on(e : AEvent) : Function {


		var sn = "s1-on";
		if (e != EMPTY_EVT)
		{
				_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{   trace("on");
				this.light_mc.gotoAndPlay ("on");
				return null;
			}
			case EXIT_EVT :
			{
				trace("leaving on");
				this.light_mc.gotoAndStop ("unknown");
				return null;
			}

			case TOGGLE_SIG :
			{
				this.Q_TRAN (this.s1_dimmingDown);
				return null;
			}
		}
		return s_top;
	}
	public function s1_dimmingUp(e : AEvent) : Function {


		var sn = "s1-dimmingUp";
		if (e != EMPTY_EVT)
		{
				_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{   trace("dimming Up");
				//this.startPulse(1000/12);
				this.light_mc.gotoAndPlay ("dimmingUp");
				return null;
			}
			case DIMMEDUP_SIG:{
				//this.stopPulse();
				this.Q_TRAN (this.s1_on);
				return null;
			}
			
			case EXIT_EVT :
			{
				trace("dimmed Up");
				
				return null;
			}
		}
		return s_top;
	}
	public function s1_dimmingDown(e : AEvent) : Function {


		var sn = "s1-s1_dimmingDown";
		if (e != EMPTY_EVT)
		{
				_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{   trace("dimming Down");
				//this.startPulse(1000/12);
				this.light_mc.gotoAndPlay ("dimmingDown");
				return null;
			}
			case DIMMEDDOWN_SIG:{
				//this.stopPulse();
				this.Q_TRAN (this.s1_off);
				return null;
			}
			
			case EXIT_EVT :
			{
				trace("dimmed Down");
				
				return null;
			}
		}
		return s_top;
	}
	public function s1_off(e : AEvent) : Function {

		
		var sn = "s1-off";
		if (e != EMPTY_EVT)
		{
				_global.outText (sn + e);
		}
		switch (e)
		{
			case ENTRY_EVT :
			{	trace("off");
				this.light_mc.gotoAndPlay ("off");
				return null;
			}
			case EXIT_EVT :
			{
				trace("leaving off");
				this.light_mc.gotoAndStop ("unknown");
				return null;
			}

			case TOGGLE_SIG :
			{
				this.Q_TRAN (this.s1_dimmingUp);
				return null;
			}
		}
		return s_top;
	}


	public function dispatch(evt : AEvent) : Void {
	}

}